#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 文件名：12-对象.py

class Employee:
    # 类变量，所以实例都可以访问，相当于公共变量
    empCount = 0
    
    # 构造函数__init__固定的名称，类方法比普通的函数多了第一个参数self
    def __init__(self, name, salary):
        self.name1 = name
        self.salary1 = salary
        
        # 访问类变量需要加上类名称
        Employee.empCount += 1

    def displayCount(self): 
        print Employee.empCount
        
    def displayEmp(self):
        print "员工{0}的薪水{1}".format(self.name1, self.salary1)

emp1 = Employee("tom", 1000)
emp2 = Employee("jack", 2000)

emp1.displayCount()
emp2.displayEmp()

print "员工数量{0} ".format(Employee.empCount)



"""A class that can be used to represent a car."""

class Car():
    """A simple attempt to represent a car."""

    def __init__(self, manufacturer, model, year):
        """Initialize attributes to describe a car."""
        self.manufacturer = manufacturer
        self.model = model
        self.year = year
        self.odometer_reading = 0
        
    def get_descriptive_name(self):
        """Return a neatly formatted descriptive name."""
        long_name = str(self.year) + ' ' + self.manufacturer + ' ' + self.model
        return long_name.title()
    
    def read_odometer(self):
        """Print a statement showing the car's mileage."""
        print("This car has " + str(self.odometer_reading) + " miles on it.")
        
    def update_odometer(self, mileage):
        """
        Set the odometer reading to the given value.
        Reject the change if it attempts to roll the odometer back.
        """
        if mileage >= self.odometer_reading:
            self.odometer_reading = mileage
        else:
            print("You can't roll back an odometer!")
    
    def increment_odometer(self, miles):
        """Add the given amount to the odometer reading."""
        self.odometer_reading += miles
